%% process_showmesh
function process_showmesh(mesh, fespace, varargin)
node = mesh.node;
elem = mesh.elem;
Np = mesh.Np;
Ne = mesh.Ne;
Nf = mesh.Nf;
Ned = mesh.Ned;
figure("WindowStyle", "docked");
tetramesh(elem, node, "FaceColor", "none");
hold on;
% node
if isempty(varargin) || varargin{1}(1) == 1
    plot3(node(:,1), node(:,2), node(:,3), "k.", "MarkerSize", 10);
    text(node(:,1), node(:,2), node(:,3), num2str((1:Np)'), "FontSize", 10, "FontWeight", "bold", "Color", "k", "HorizontalAlignment", "right", "VerticalAlignment", "bottom");
    if fespace.basis_type == "P2"
        node = fespace.node;
        Nb = fespace.Nb;
        plot3(node(Np+1:end,1), node(Np+1:end,2), node(Np+1:end,3), "k.", "MarkerSize", 10);
        text(node(Np+1:end,1), node(Np+1:end,2), node(Np+1:end,3), num2str((Np+1:Nb)'), "FontSize", 10, "FontWeight", "bold", "Color", "k", "HorizontalAlignment", "right", "VerticalAlignment", "bottom");
    end
end
% elem
if isempty(varargin) || varargin{1}(2) == 1
    centroid = zeros(Ne,3);
    for e = 1:Ne
        V = node(elem(e,:),:);
        centroid(e,:) = mean(V,1);
    end
    text(centroid(:,1), centroid(:,2), centroid(:,3), num2str((1:Ne)'), "FontSize", 10, "FontWeight", "bold", "Color", "r");
end
% face
if isempty(varargin) || varargin{1}(3) == 1
    centroid = zeros(Nf,3);
    for e = 1:Nf
        V = node(mesh.tri(e,2:4),:);
        centroid(e,:) = mean(V,1);
    end
    text(centroid(:,1), centroid(:,2), centroid(:,3), num2str((1:Nf)'), "FontSize", 10, "FontWeight", "bold", "Color", "g");
end
% edge
if isempty(varargin) || varargin{1}(4) == 1
    midpoint = 0.5*(node(mesh.edge(:,1),:) + node(mesh.edge(:,2),:));
    text(midpoint(:,1), midpoint(:,2), midpoint(:,3), int2str((1:Ned)'), "FontSize", 10, "FontWeight", "bold", "Color", "b");
end
hold off;
xlabel("X");
ylabel("Y");
zlabel("Z");
axis("equal", "tight");
view(120, 30);
end